/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            aRoomDetailRoomInfo: {
                rooms: [],
                ownerId: '',
                roomId:'',
                roomNum: '',
                allOweFeeAmount: '0'
            }
        },
        _initMethod: function () {
        },
        _initEvent: function () {
            vc.on('aRoomDetailRoom', 'switch', function (_data) {
                $that.aRoomDetailRoomInfo.ownerId = _data.ownerId;
                $that.aRoomDetailRoomInfo.roomId = _data.roomId;
                $that._loadARoomDetailRoomData(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('aRoomDetailRoom', 'paginationPlus', 'page_event',
                function (_currentPage) {
                    vc.component._loadARoomDetailRoomData(_currentPage, DEFAULT_ROWS);
                });
            vc.on('aRoomDetailRoom', 'notify', function (_data) {
                $that._loadARoomDetailRoomData(DEFAULT_PAGE, DEFAULT_ROWS);
            })
        },
        methods: {
            _loadARoomDetailRoomData: function (_page, _row) {
                if(!$that.aRoomDetailRoomInfo.ownerId){
                    return;
                }
                let param = {
                    params: {
                        ownerId: $that.aRoomDetailRoomInfo.ownerId,
                        roomNum: $that.aRoomDetailRoomInfo.roomNum,
                        roomId: $that.aRoomDetailRoomInfo.roomId,
                        page: _page,
                        row: _row
                    }
                };
                //发送get请求
                vc.http.apiGet('/room.queryAdminOwnerRooms',
                    param,
                    function (json) {
                        let _json = JSON.parse(json);
                        vc.component.aRoomDetailRoomInfo.rooms = _json.rooms;
                        vc.emit('aRoomDetailRoom', 'paginationPlus', 'init', {
                            total: _json.records,
                            dataCount: _json.total,
                            currentPage: _page
                        });
                    },
                    function () {
                        console.log('请求失败处理');
                    }
                );
            },
            //查询
            _qureyARoomDetailRoom: function () {
                $that._loadARoomDetailRoomData(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            //重置
            _resetARoomDetailRoom: function () {
                vc.component.aRoomDetailRoomInfo.roomNum = "";
                $that._loadARoomDetailRoomData(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _toAdminRoomDetail: function (_room) {
                window.open('/#/pages/community/adminRoomDetail?roomId='+_room.roomId);
            },
        }
    });
})(window.vc);